<template>
  <!-- 详情开始 -->
  <a-modal
    :maskClosable="false"
    title="候选人列表"
    :width="1200"
    :bodyStyle="{
      padding: '0 24px'
    }"
    :visible="visible"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card
      :bordered="false"
      :bodyStyle="{
        padding: '10px 24px'
      }">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchByquery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="候选人" :labelCol="{xs: { span: 24 },sm: { span: 5 }}" :wrapperCol="{xs: { span: 24 },sm: { span: 12 }}">
                <a-input-search placeholder="选择候选人" readOnly @search="handleSelect" v-model="model.userId">
                  <a-button slot="enterButton" icon="search">选择</a-button>
                </a-input-search>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchByquery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
      <!-- 查询区域-END -->

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          rowKey="id"
          bordered
          :scroll="{x: '100%'}"
          :components="draggableComponent"
          :columns="dragResizeColumns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          wrapClassName="ant-modal-cust-warp"
          @change="handleTableChange">
          <span slot="action" slot-scope="text, record">
            <template >
              <a-popconfirm :title="'确定忽略吗？'" @confirm="() => ignoreRecord(record)">
                <a-button size="small"  type="primary" >忽略</a-button>
              </a-popconfirm>
            </template>
          </span>
          
        </a-table>
      </div>
      <!-- 详情结束 -->
    </a-card>
    <template slot="footer">
      <a-button @click.stop="()=>{visible=false}">关闭</a-button>
    </template>
    <select-single-user-modal ref="selectSingleUserModal" @selectFinished="selectUserOK"></select-single-user-modal>
  </a-modal>
  <!-- 详情结束 -->
</template>

<script>

  import { filterObj } from '@/utils/util';
  import { getAction,postAction,putAction,getFileAccessHttpUrl } from '@/api/manage'
  import { DragResizable } from '@/mixins/DragResizable'
  import SelectSingleUserModal from "./form/SelectSingleUserModal.vue";
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'ErpFinanceKingdeeCollectMoneyBillListPenetrate',
    components: {
      SelectSingleUserModal
    },
    mixins: [DragResizable],
    data() {
      return {
        taskId:"",
        createTimeRange:[],
        model:{
          userId:""
        },
        visibleDetail: false,
        title: '收款明细',
        queryParam: {},
        toggleSearchStatus: false,
        dragResizeColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'任务ID',
            align:"center",
            width:200,
            ellipsis: true,
            dataIndex: 'taskId',
          },
          {
            title:'候选人',
            align:"center",
            width:200,
            ellipsis: true,
            dataIndex: 'userId',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['sysuser'], text + '')
              }
            }

          },
          {
            title:'类型',
            align:"center",
            width:200,
            ellipsis: true,
            dataIndex: 'type',
            customRender: (text) => {
              switch(text) {
                case 'candidate':
                  return '候选者';
                case 'participant':
                  return '参与者';
              }
              return text;
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:100,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          ignore: '/api/erpmng/act/task/ignore',
          candidateTaskList:"/api/erpmng/act/task/candidateTaskList",
          invalidRecord:"/api/erp/finance/record/erpFinancePaymentAgainstDocumentsRecord/invalidDocument",
          urlList: '/api/erp/finance/record/erpFinancePaymentAgainstDocumentsRecord/allList',
          queryById: '/api/erp/finance/record/erpFinancePaymentAgainstDocumentsRecord/queryById'
        },
        dataSource: [],
        loading: false,
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        isorter: {
          column: 'createTime',
          order: 'desc'
        },
        scrollTrigger: { x: true },
        visible: false,
        dictOptions: {},
      }
    },
    created() {
      this.loadData();
      // 该方法触发屏幕自适应
      this.resetScreenSize();
      this.refresh();
      // 加载数据字典信息
      this.initDictConfig();
      this.dragResizeColumnswidth = this.dragResizeColumns.map(val => {
        return val.width
      })
    },
    computed: {
    },
    methods: {
      ignoreRecord(record){
        let that=this;
        var params = { taskId: record.taskId,userId:record.userId };// 查询条件
        putAction(that.url.ignore, params).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            this.loadData(1)
          } else {
            that.$message.warning(res.message);
          }
        })
      },
      searchReset() {
        this.queryParam = {}
        this.model = {};
        this.loadData(1)
      },
      handleSelect: function(){
        this.$refs.selectSingleUserModal.select();
      },
      selectUserOK: function(data){
        this.$set(this.model, 'userId',  data.realname)
        this.queryParam.userId = data.username;
      },
      invalidRecord(record){
        postAction(this.url.invalidRecord,record).then(res=>{
          if (res.success) {
              this.$message.success(res.message)
              this.loadData();
            }else{
              this.$message.error(res.message)
            }
        })
      },
      initDictConfig() {
        initDictOptions('sys_user,realname,username').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'sysuser', res.result)
          }
        })
      },
      handleCancelDetail() {
        this.visible = true
        this.visibleDetail = false
      },
      handleToggleSearch() {
        this.toggleSearchStatus = !this.toggleSearchStatus;
      },
      handleTableChange(pagination, filters, sorter) {
      // 分页、排序、筛选变化时触发
        this.filters = {}
        if (Object.keys(filters).length > 0) {
          for (let key in filters) {
            let value = filters[key].join(',')
            if (value) {
              if (key.indexOf('_dictText') != -1) {
                key = key.substring(0, key.indexOf('_dictText'))
              }
              this.filters[key] = value
            }
          }
        }
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field
          this.isorter.order = sorter.order == 'ascend' ? 'asc' : 'desc'
        }
        this.ipagination = pagination
        this.loadData()
      },
      loadData(arg) {
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();// 查询条件
        if (!this.taskId) {
          this.dataSource = []
          this.ipagination.total = 0
          return
        } else {
          params.taskId = this.taskId;
        }
        getAction(this.url.candidateTaskList, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
            // 判断是否当前页没有数据且不为第一页
            if (this.dataSource.length == 0 && this.ipagination.current != 1) {
              this.ipagination.current = this.ipagination.current - 1
              this.loadData(this.ipagination.current - 1);
            } else {
              this.loading = false
            }

          }
        })
      },
      getQueryParams() {
        let param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return filterObj(param);
      },
      getQueryField() {
        let str = 'id,';
        for (let a = 0; a < this.dragResizeColumns.length; a++) {
          str += ',' + this.dragResizeColumns[a].dataIndex;
        }
        return str;
      },
      searchByquery() {
        this.loadData(1);
      },
      refresh() {
        this.loading = true
      },
      open(record) {
        this.loadData(1);
      },
      // 触发屏幕自适应
      resetScreenSize() {
        let screenWidth = document.body.clientWidth;
        if (screenWidth < 500) {
          this.scrollTrigger = { x: 800 };
        } else {
          this.scrollTrigger = {};
        }
      },
      handleCancel() {
        this.visible = false;
      },
      handleOk() {
        this.handleCancel();
      },
    }
  }
</script>
<style scoped>
  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }

  .anty-img-wrap {
    height: 25px;
    position: relative;
  }

  .anty-img-wrap > img {
    max-height: 100%;
  }

</style>